package cn.itsource.org.service.impl;

import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.domain.Shop;

import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.mapper.ShopMapper;
import cn.itsource.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {
@Autowired
 private  ShopMapper shopMapper;
@Autowired
private EmployeeMapper employeeMapper;

    @Override
    public void settlement(Shop shop) {
        //从商铺中拿到店长信息
        Employee admin = shop.getAdmin();
        //保存店长信息到员工表中  此时有他员工的id，sql语句自增，但是没有他关联店铺的
        employeeMapper.save(admin);
        //保存店铺对象到店铺表中 此时有店铺id，sql语句自增，因为shop包含了admin，所以也就有他对应店长的id，此时店铺表全
        shopMapper.save(shop);
        //在员工表中，将shop的对象增加到店长里
        admin.setShop(shop);
        //在员工中修改店长信息，增加shop_id  因为在第二步时没有店铺id，这一步吧id加进去
        //shop_id=#{shop.id}
        employeeMapper.update(admin);
    }
}
